# 给定以下列表, 通过**匿名函数**和**常规函数**根据键`age`来排序
classes = [
    {"name": "abyss", "age": 25, "grade": "A"},
    {"name": "kin", "age": 23, "grade": "B"},
    {"name": "tian", "age": 24, "grade": "B"},
    {"name": "hun", "age": 26, "grade": "A"},
    {"name": "exe", "age": 21, "grade": "A"}
]


# 常规函数
def my_general_sort(x):
    return x["age"]


my_result = sorted(classes, key=my_general_sort, reverse=False)
print(f'常规函数排序:{my_result}')

# 匿名函数
print(f'匿名函数排序:{sorted(classes, key=lambda x: x["age"], reverse=False)}')

# 2021年马上就要到来了, 通过`map`函数将上述同学的`age`+1
change_age = map(lambda x: x["age"]+1, classes)
print(list(change_age))

# 通过`filter`函数过滤掉上述同学中`grade`是`A`的同学
my_filter = filter(lambda x: x["grade"] != "A", classes)
print(list(my_filter))


# 使用递归来重构斐波那契函数
def my_fib(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return my_fib(n-1) + my_fib(n-2)


print(my_fib(10))




